package com.ruoyi.system.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DosingTypeMapper;
import com.ruoyi.system.domain.DosingType;
import com.ruoyi.system.service.IDosingTypeService;

/**
 * 备料类型Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-13
 */
@Service
public class DosingTypeServiceImpl extends ServiceImpl<DosingTypeMapper,DosingType> implements IDosingTypeService
{
    @Autowired
    private DosingTypeMapper dosingTypeMapper;

    /**
     * 查询备料类型
     * 
     * @param id 备料类型主键
     * @return 备料类型
     */
    @Override
    public DosingType selectDosingTypeById(Long id)
    {
        return dosingTypeMapper.selectDosingTypeById(id);
    }

    /**
     * 查询备料类型列表
     * 
     * @param dosingType 备料类型
     * @return 备料类型
     */
    @Override
    public List<DosingType> selectDosingTypeList(DosingType dosingType, Integer pageNum, Integer pageSize)
    {
        LambdaQueryWrapper<DosingType> queryWrapper = new LambdaQueryWrapper<>();
        if (dosingType.getDosingId() != null)
        {
            queryWrapper.eq(DosingType::getDosingId, dosingType.getDosingId());
        }
        return baseMapper.selectPage(new Page<>(pageNum,pageSize),queryWrapper).getRecords();
    }

    @Override
    public Long selectDosingTypeCount(DosingType dosingType) {
        LambdaQueryWrapper<DosingType> queryWrapper = new LambdaQueryWrapper<>();
        if (dosingType.getDosingId() != null)
        {
            queryWrapper.eq(DosingType::getDosingId, dosingType.getDosingId());
        }
        return baseMapper.selectCount(queryWrapper);
    }

    @Override
    public List<DosingType> selectDosingTypeAll(DosingType dosingType)
    {
        return dosingTypeMapper.selectDosingTypeList(dosingType);
    }
    /**
     * 新增备料类型
     * 
     * @param dosingType 备料类型
     * @return 结果
     */
    @Override
    public int insertDosingType(DosingType dosingType)
    {
        dosingType.setCreateTime(LocalDateTime.now());
        return dosingTypeMapper.insertDosingType(dosingType);
    }

    /**
     * 修改备料类型
     * 
     * @param dosingType 备料类型
     * @return 结果
     */
    @Override
    public int updateDosingType(DosingType dosingType)
    {
        dosingType.setUpdateTime(LocalDateTime.now());
        return dosingTypeMapper.updateDosingType(dosingType);
    }

    /**
     * 批量删除备料类型
     * 
     * @param ids 需要删除的备料类型主键
     * @return 结果
     */
    @Override
    public int deleteDosingTypeByIds(Long[] ids)
    {
        return dosingTypeMapper.deleteDosingTypeByIds(ids);
    }

    /**
     * 删除备料类型信息
     * 
     * @param id 备料类型主键
     * @return 结果
     */
    @Override
    public int deleteDosingTypeById(Long id)
    {
        return dosingTypeMapper.deleteDosingTypeById(id);
    }
}
